<include file="public/layout" />
<body style="background-color: #FFF; overflow: auto;">

<div class="page" style="height: 100%">

    <form class="layui-form" action="">
        <input type="hidden" name="id" value="{$info.id}" />
        <div class="layui-form-item">
            <label class="layui-form-label" style="width:130px">标题：</label>
            <div class="layui-input-inline layui-input-wrap">
                <input type="text" name="title" lay-verify="required" value="{$info['title']}" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width:130px">模板编号：</label>
            <div class="layui-input-inline layui-input-wrap">
                <input type="text" name="template_sn" lay-verify="required" value="{$info['template_sn']}" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width:130px">模板ID：</label>
            <div class="layui-input-inline layui-input-wrap">
                <input type="text" name="template_id" lay-verify="required" value="{$info['template_id']}" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width:130px">通知类型：</label>
            <div class="layui-input-inline" style="width:300px">
                <select name="type">
                    <foreach name="$tpl_type_arr" item="type_name" key="type">
                        <option value="{$type}">{$type_name}</option>
                    </foreach>
                </select>>
            </div>
            <div class="layui-form-mid layui-word-aux"></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width:130px">状态：</label>
            <div class="layui-input-block">
                <input type="radio" name="status" value="0" title="关闭" <if condition="$info['status'] eq '0'">checked</if> >
                <input type="radio" name="status" value="1" title="开启" <if condition="$info['status'] eq '1'">checked</if> >
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit lay-filter="demo1">确认</button>
            </div>
        </div>
    </form>

</div>
<script>
    layui.use(function(){
        var form = layui.form;
        var layer = layui.layer;
        var laydate = layui.laydate;
        var util = layui.util;

        // 自定义验证规则
        form.verify({
            pass: [
                /^[\S]{6,12}$/,
                '密码必须6到12位，且不能出现空格'
            ]
        });
        // 提交事件
        form.on('submit(demo1)', function(data){
            var index = layer.load();
            layer.close(index);

            var field = data.field; // 获取表单字段值
            $.ajax({
                type: "POST",
                url: "{:url('edit')}",
                data: field,
                success: function(res){
                    console.log(res);
                    if(res.status){
                        layer.msg('提交成功');
                    }else{
                        layer.msg(res.msg);
                    }
                    setTimeout(function(){
                        parent.layer.closeAll();
                        parent.tableIns.reload()
                    },1000)
                }
            });
            return false; // 阻止默认 form 跳转
        });

        // 日期
        laydate.render({
            elem: '#date'
        });


    });
    layui.upload.render({
        elem: '.uploadjstxt', //绑定元素
        url: "{:url('Upload/uploadjstxt')}", //上传接口
        accept:'file',
        data:{type:'wx'},
        done: function(res){
            //上传完毕回调
            console.log(res)
            $('input[name="config['+res.field+']"]').val(res.file_path);
            $('#'+res.field+'_text').text('已上传')
            dialog(res.msg,res.status)
        },
        error: function(){
            //请求异常回调
        }
    });
</script>
</body>
</html>